﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace AlarmClock
{
    class AlarmClock
    {
        private static long hour = 0;
        private static long minute = 0;
        private static long second = 0;
        private static long hour1 = 0;
        private static long minute1 = 0;
        private static long second1 = 0;

        public event Action<Object> Tick = delegate
        {
            ++second;
            if (second >= 60)
            {
                minute += 1;
                second = 0;
            }
            if (minute >= 60)
            {
                hour += 1;
                minute = 0;
            }
            if (hour >= 24)
                hour = 0;
            Console.WriteLine("Clock Tick");
            Console.WriteLine($"Time: {hour.ToString("00")} : {minute.ToString("00")} : {second.ToString("00")}");

        };

        public event Action<Object> Alarm =
            delegate (Object obj)
            {
                if (hour1 == hour && minute1 == minute && second1 == second)
                {
                    Console.WriteLine("Clock Alarming !!");
                }
            };

        public void Run()
        {
            while (true)
            {
                Tick(this);
                Alarm(this);
                Thread.Sleep(1000);
                Console.Clear();
            }
        }

        public void Run(long newhour, long newmin, long newsec)
        {
            hour = newhour;
            minute = newmin;
            second = newsec;
        }

        public void SetAlarm(long h, long m, long s)
        {
            hour1 = h;
            minute1 = m;
            second1 = s;
        }
    }

    class Form
    {
        public AlarmClock clk = new AlarmClock();

        public void SetTime(long h, long m, long s)
        {
            clk.Run(h, m, s);
        }

        public void SetAlarm(long h, long m, long s)
        {
            clk.SetAlarm(h, m, s);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Form f1 = new Form();
            f1.SetTime(0, 0, 0);
            f1.SetAlarm(0, 0, 10);
            f1.clk.Run();
        }
    }
}
